package com.atguigu.gmall.activity.controller;

import com.atguigu.gmall.activity.service.ActivityRuleService;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.activity.ActivityRuleVo;
import com.atguigu.gmall.model.product.SkuInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: zm
 * @Date: 2021/8/15 19:30
 */

@RestController
@RequestMapping("admin/activity/activityInfo")
public class ActivityRuleController {


    @Autowired
    private ActivityRuleService activityRuleService;

    /**
     * 活动规则List
     *
     * @param id
     * @return
     */
    // http://localhost/admin/activity/activityInfo/findActivityRuleList/2
    @GetMapping("findActivityRuleList/{id}")
    public Result findActivityRuleList(@PathVariable Long id) {
        Map<String, Object> activityRuleList = activityRuleService.findActivityRuleList(id);
        return Result.ok(activityRuleList);
    }

    /**
     * 获取SkuInfo 列表
     */
    //http://localhost/admin/activity/activityInfo/findSkuInfoByKeyword/{keyWord}
    @GetMapping("findSkuInfoByKeyword/{keyWord}")
    public  Result findSkuInfoByKeyword(@PathVariable("keyWord") String keyWord){
        List<SkuInfo> list = activityRuleService.findSkuInfoByKeyword(keyWord);
        return Result.ok(list);
    }

    /**
     * 保存ActivityRule
     * @param activityRuleVo
     * @return
     */
   // http://localhost/admin/activity/activityInfo/saveActivityRule
    @PostMapping("saveActivityRule")
    public Result saveActivityRule(@RequestBody ActivityRuleVo activityRuleVo){
        activityRuleService.saveActivityRule(activityRuleVo);
        return Result.ok();
    }


}
